package com.yxzx.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yxzx.api.dto.RestStatusCode;
import com.yxzx.api.entity.Banner;
import com.yxzx.api.exception.CustomException;
import com.yxzx.api.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 广告轮播 前端控制器
 * </p>
 *
 * @author YWB
 * @since 2020-09-06
 */
@RestController
@RequestMapping("/api/banner")
public class BannerController {


    @Autowired
    private IBannerService bannerService;

    @GetMapping("/getBanner")
    public ResponseEntity<List<Banner>> getBannerList(){

        try{
            QueryWrapper queryWrapper=new QueryWrapper();

            queryWrapper.eq("deleted",0);

            List<Banner> banners = bannerService.list(queryWrapper);


            return ResponseEntity.ok(banners);
        }catch(Exception e){

            throw new CustomException("", RestStatusCode.Banner_QUERY_ERROR.getCode(),RestStatusCode.Banner_QUERY_ERROR.getMessage());
        }
    }

}
